/*
 *  parser.c
 *  
 *
 *  Created by Theron Rodgers on 4/29/08.
 *  NEW STUFF BEGINS ON LINE 454
 *  So far, have only done MOV, ADD, MULTI, and DIV
 */

#include "parser.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

//Declaration of list type
struct list {
	struct token *head;
	struct token *tail;
};
//Prototypes for included functions
void tokenizer(char *tokens, struct list *ll);
struct list *new_list();
int find_char(char *tok);
void print_list(FILE *fp, struct list *ll);
struct reg new_reg();
//Declaration of variable to track line numbers
static int linecount = 0;

//Function to read input and divide it into tokens
void scan( FILE *fp, struct list *ll) {

	char line[LINE_MAX];
	char *tok;
	
	//splits lines of input into tokens
	while (fgets(line, LINE_MAX, fp) != NULL)	{
	
		tok = strtok (line, " \n\t");
		//creates token objects from input
		while(tok != NULL)	{

			tokenizer(tok, ll);
			tok = strtok (NULL, " ");
		}
		linecount++;
	}
}
//Prints a list in formatted output
void print_list(FILE *fp, struct list *ll)	{

	struct token *tok;
	//Travels through list and prints each node
	for( tok = ll->head; tok != NULL; tok = tok->next){
		//Prints tokens of type INTEGER
		if(tok->type == INTEGER)	{
		
			fprintf(fp, "The value of this token is %d and its type is INTEGER\n", tok->v.i);
		}
		//Prints tokens of type FLOAT
		else if (tok->type == FLOAT)	{
		
			fprintf(fp, "The value of this token is %f and its type is FLOAT\n", tok->v.f);
		}
		//Prints tokens of type REGISTER
		else if (tok->type == REGISTER)	{
		
			if(tok->v.r == R1)	{
			
				fprintf(fp, "The value of this token is R1 and its type is REGISTER\n");
			}
			if(tok->v.r == A)	{
			
				fprintf(fp, "The value of this token is A and its type is REGISTER\n");
			}
			if(tok->v.r == R2)	{
			
				fprintf(fp, "The value of this token is R2 and its type is REGISTER\n");
			}
			if(tok->v.r == R3)	{
			
				fprintf(fp, "The value of this token is R3 and its type is REGISTER\n");
			}
			if(tok->v.r == R4)	{
			
				fprintf(fp, "The value of this token is R4 and its type is REGISTER\n");
			}
			if(tok->v.r == R5)	{
			
				fprintf(fp, "The value of this token is R5 and its type is REGISTER\n");
			}
			if(tok->v.r == R6)	{
			
				fprintf(fp, "The value of this token is R6 and its type is REGISTER\n");
			}
			if(tok->v.r == R7)	{
			
				fprintf(fp, "The value of this token is R7 and its type is REGISTER\n");
			}
			
		}
		//Prints tokens of type OPCODE
		else if (tok->type == OPCODE)	{
		
			if(tok->v.op ==BEGIN)	{
			
				fprintf(fp, "The value of this token is BEGIN and its type is OPCODE\n");
			}
			if(tok->v.op ==END)	{
			
				fprintf(fp, "The value of this token is END and its type is OPCODE\n");
			}
			if(tok->v.op ==MOVE)	{
			
				fprintf(fp, "The value of this token is MOVE and its type is OPCODE\n");
			}
			if(tok->v.op ==ANL)	{
			
				fprintf(fp, "The value of this token is ANL and its type is OPCODE\n");
			}
			if(tok->v.op ==ORL)	{
			
				fprintf(fp, "The value of this token is ORL and its type is OPCODE\n");
			}
			if(tok->v.op ==XRL)	{
			
				fprintf(fp, "The value of this token is XLR and its type is OPCODE\n");
			}
			if(tok->v.op ==SWAP)	{
			
				fprintf(fp, "The value of this token is SWAP and its type is OPCODE\n");
			}
			if(tok->v.op ==CLR)	{
			
				fprintf(fp, "The value of this token is CLR and its type is OPCODE\n");
			}
			if(tok->v.op ==SETB)	{
			
				fprintf(fp, "The value of this token is SETB and its type is OPCODE\n");
			}
			if(tok->v.op ==SJMP)	{
			
				fprintf(fp, "The value of this token is SJMP and its type is OPCODE\n");
			}
			if(tok->v.op ==JZ)	{
			
				fprintf(fp, "The value of this token is JZ and its type is OPCODE\n");
			}
			if(tok->v.op ==ADD)	{
			
				fprintf(fp, "The value of this token is ADD and its type is OPCODE\n");
			}
			if(tok->v.op ==MULT)	{
			
				fprintf(fp, "The value of this token is MULT and its type is OPCODE\n");
			}
			if(tok->v.op ==DIV)	{
			
				fprintf(fp, "The value of this token is DIV and its type is OPCODE\n");
			}
			if(tok->v.op ==DISP)	{
			
				fprintf(fp, "The value of this token is DISP and its type is OPCODE\n");
			}
			if(tok->v.op ==MINUS)	{
			
				fprintf(fp, "The value of this token is DISP and its type is OPCODE\n");
			}
			if(tok->v.op ==INPT)	{
			
				fprintf(fp, "The value of this token is INPT and its type is OPCODE\n");
			}
		}
	}
}

//Constructor for a new token object
struct token *new_token(union value v_new, enum lexeme type_new, int linenum_new)	{
	//Allocates memory
	struct token *t = (struct token *) malloc (sizeof (struct token));
	//Adds data to each component of token struct
	t->v = v_new;
	t->type = type_new;
	t->linenum = linenum_new;
	t->next = NULL;
}
//Constructor for a new list object
struct list *new_list ()
{
	//Allocates memory
	struct list *ll = (struct list *) malloc (sizeof (struct list));
	//Creates two nodes
	ll->head = NULL;
	ll->tail = NULL;

	return ll;
}

struct reg new_reg()	{

	struct reg *registers =(struct reg *)  malloc(sizeof(struct reg));
	registers->v.i = 0.0;
	registers->v.f = 0.0;
	registers->v.r = (enum registerz)NULL;
	registers->v.op = (enum opcode)NULL;
	registers->type = (enum lexeme )NULL;
	
	return *registers;
}
//Frees the memory in a token
void delete_token (struct token *n)
{
	free (n);
}

//Deletes an entire list
void delete_list (struct list *ll)
{
	struct token *pos = ll->head;
	struct token *old;

	/* free all the nodes in the list */
	while (pos != NULL) {
		old = pos;

		pos = pos->next;

		delete_token (old);
	}

	/* free the list itself */
	free (ll);
}

//Adds a token to list
void list_pushback (struct list *ll, union value u, enum lexeme type, int linenum)	{
	if (ll->head == NULL) {	
		/* list is empty, so start at beginning */
		ll->head = ll->tail = new_token(u, type, linenum);
	}
	else {
		ll->tail = ll->tail->next = new_token(u, type, linenum);
	}
}

//Determines what type of token input is and adds to list
void tokenizer (char *futureTokens, struct list *stuff)	{

	union value newvalue;
	enum lexeme type;
	int linenum;
	//Catches input if is of type REGISTER
	if (strcmp(futureTokens, "A") == 0)	{
		//Creates a token with required information and adds it to list
		newvalue.r = A;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);

	}
	else if (strcmp(futureTokens, "R1") ==0)	{
		
		newvalue.r = R1;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "R2") ==0)	{
	
		newvalue.r = R2;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "R3") == 0)	{
	
		newvalue.r = R3;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "R4") == 0)	{
	
		newvalue.r = R4;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "R5") == 0)	{
	
		newvalue.r = R5;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "R6") == 0)	{
	
		newvalue.r = R6;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "R7") == 0)	{
	
		newvalue.r = R7;
		type = REGISTER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	//Catches input if type OPCODE
	else if (strcmp(futureTokens, "BEGIN") == 0)	{
	
		newvalue.op = BEGIN;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "END") == 0)	{

		newvalue.op = END;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "MOV") == 0)	{
	
		newvalue.op = MOVE;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "ANL") == 0)	{
	
		newvalue.op = ANL;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "ORL") == 0)	{
	
		newvalue.op = ORL;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "XLR") == 0)	{
	
		newvalue.op = XRL;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "SWAP") == 0)	{
	
		newvalue.op = SWAP;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "CLR") == 0)	{
	
		newvalue.op = CLR;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	
	else if (strcmp(futureTokens, "SETB") == 0)	{
	
		newvalue.op = SETB;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "JZ") == 0)	{
	
		newvalue.op = JZ;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "ADD") == 0)	{
	
		newvalue.op = ADD;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "MULT") == 0)	{
	
		newvalue.op = MULT;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "DIV") == 0)	{
	
		newvalue.op = DIV;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "EXP") == 0)	{
	
		newvalue.op = EXP;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "DISP") == 0)	{
	
		newvalue.op = DISP;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "POWR") == 0)	{
	
		newvalue.op = POWR;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "MINUS") == 0)	{
	
		newvalue.op = MINUS;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "GET") == 0)	{
	
		newvalue.op = GET;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "INPT") == 0)	{
	
		newvalue.op = INPT;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "SQRT") == 0)	{
	
		newvalue.op = SQRT;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "DEC") == 0)	{
	
		newvalue.op = DEC;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "LOOP") == 0)	{
	
		newvalue.op = LOOP;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "LOAD") == 0)	{
	
		newvalue.op = LOAD;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	else if (strcmp(futureTokens, "BRA") == 0)	{
	
		newvalue.op = BRA;
		type = OPCODE;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	//Catches input if of type float
	else if (LONG_MIN < (float)*futureTokens < LONG_MAX  && (int)strchr(futureTokens, '.') != NULL && strchr(futureTokens, '.') ==strrchr(futureTokens, '.') && find_decimal(futureTokens) == 1)	{
		
		newvalue.f =atof(futureTokens);
		type = FLOAT;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	//Catches input if of type int
	else if (INT_MIN <= (int)*futureTokens <= INT_MAX && find_char(futureTokens) == 1)	{

		newvalue.i =  atoi(futureTokens);
		type = INTEGER;
		linenum = linecount;
		list_pushback(stuff, newvalue, type, linenum);
	}
	//Returns an error message for all other inputs
	else {
		fprintf(stderr, "The token at line %d is not formatted correctly.\n", linecount);
	}
}
// funciton to determine the reigster index from given value, might not be necessary
int determine_register(enum registerz r)	{

	int r_number;
	if (r == A) {
		r_number = 0;
	}
	else if (r == R1) {
		r_number = 1;
	}
	else if (r == R2) {
		r_number = 2;
	}
	else if (r == R3) {
		r_number = 3;
	}
	else if (r == R4) {
		r_number = 4;
	}
	else if (r == R5) {
		r_number = 5;
	}
	else if (r == R6) {
		r_number = 6;
	}
	else if (r == R7) {
		r_number = 7;
	}
	
	return r_number;
}


//Main part of parser seperate from lexer, I just lumped it in with the rest of the lexer for ease of use, although it might be good to seperate
void run_program(FILE *fp, struct list *ll)	{

	struct token *tok = ll->head;
	struct reg *registers[10];
	int i, j;
	for (j = 0; j < 10; j++)	{
		registers[j] = (struct reg *) malloc(sizeof(struct reg));
	}
	for (j = 0; j < linecount; j++) {
	
		if(tok->type == OPCODE && tok->v.op == MOVE) {
			
			if (tok->next->type == REGISTER && tok->next->v.r == A) {
			
				if(tok->next->next->type == FLOAT)	{
					registers[0]->type = FLOAT;
					registers[0]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[0]->type = INTEGER;
					registers[0]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[0] = registers[determine_register(tok->next->next->v.r)];
					registers[0] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.op == R1) {
			
				if(tok->next->next->type == FLOAT)	{
					registers[1]->type = FLOAT;
					registers[1]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[1]->type = INTEGER;
					registers[1]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[1] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R2) {
				printf("raw dog");
				if(tok->next->next->type == FLOAT)	{
					registers[2]->type = FLOAT;
					registers[2]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
				printf("shazam");
					registers[2]->type = INTEGER;
					registers[2]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[2] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R3) {
				if(tok->next->next->type == FLOAT)	{
					registers[3]->type = FLOAT;
					registers[3]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[3]->type = INTEGER;
					registers[3]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[3] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R4) {
			
				if(tok->next->next->type == FLOAT)	{
					registers[4]->type = FLOAT;
					registers[4]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[4]->type = INTEGER;
					registers[4]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[4] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R5) {

				if(tok->next->next->type == FLOAT)	{
					registers[5]->type = FLOAT;
					registers[5]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[5]->type = INTEGER;
					registers[5]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[5] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R6) {
			
				if(tok->next->next->type == FLOAT)	{
					registers[6]->type = FLOAT;
					registers[6]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[6]->type = INTEGER;
					registers[6]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[6] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R7) {
			
				if(tok->next->next->type == FLOAT)	{
					registers[7]->type = FLOAT;
					registers[7]->v.f = tok->next->next->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == INTEGER)	{
					registers[7]->type = INTEGER;
					registers[7]->v.i = tok->next->next->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{
					registers[7] = registers[determine_register(tok->next->next->v.r)];
					tok = tok->next->next->next;
					i++;
				}
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next->next;
				i++;
			}
		}
		else if (tok->type == OPCODE && tok->v.op == ADD)	{
			
			if (tok->next->type == REGISTER && tok->next->v.r == A) {
				if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[0]->v.i = registers[0]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[0]->v.f = registers[0]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[0]->type = FLOAT;
					registers[0]->v.f = registers[0]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[0]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[0]->v.f = registers[0]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R1) {
				
				if(registers[1]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[1]->v.i = registers[1]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[1]->v.f = registers[1]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[1]->type = FLOAT;
					registers[1]->v.f = registers[1]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[1]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[1]->v.f = registers[1]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R2) {
			
				if(registers[2]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[2]->v.i = registers[2]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[2]->v.f = registers[2]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[2]->type = FLOAT;
					registers[2]->v.f = registers[2]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[2]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[2]->v.f = registers[2]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R3) {
			
				if(registers[3]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[3]->v.i = registers[3]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[3]->v.f = registers[3]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[3]->type = FLOAT;
					registers[3]->v.f = registers[3]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[3]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[3]->v.f = registers[3]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R4) {
			
				if(registers[4]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[4]->v.i = registers[4]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[4]->v.f = registers[4]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[4]->type = FLOAT;
					registers[4]->v.f = registers[4]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[4]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[4]->v.f = registers[4]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R5) {

				if(registers[5]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[5]->v.i = registers[5]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[5]->v.f = registers[5]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[5]->type = FLOAT;
					registers[5]->v.f = registers[5]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[5]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[5]->v.f = registers[5]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R6) {
			
				if(registers[6]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[6]->v.i = registers[6]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[6]->v.f = registers[6]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[6]->type = FLOAT;
					registers[6]->v.f = registers[6]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[6]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[6]->v.f = registers[6]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R7) {
			
				if(registers[7]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[7]->v.i = registers[7]->v.i + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[7]->v.f = registers[7]->v.f + registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[7]->type = FLOAT;
					registers[7]->v.f = registers[7]->v.i + registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[7]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[7]->v.f = registers[7]->v.f + registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next->next;
				i++;
			}
		}
		else if (tok->type == OPCODE && tok->v.op == MULT)	{
		
			if (tok->next->type == REGISTER && tok->next->v.r == A) {
			
				if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[0]->v.i = registers[0]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[0]->v.f = registers[0]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[0]->type = FLOAT;
					registers[0]->v.f = (float)registers[0]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[0]->v.i = (int)NULL;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[0]->v.f = registers[0]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R1) {
			
				if(registers[1]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[1]->v.i = registers[1]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[1]->v.f = registers[1]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[1]->type = FLOAT;
					registers[1]->v.f = (float)registers[1]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[1]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[1]->v.f = registers[1]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R2) {
			
				if(registers[2]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[2]->v.i = registers[2]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[2]->v.f = registers[2]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[2]->type = FLOAT;
					registers[2]->v.f = (float)registers[2]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[2]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[2]->v.f = registers[2]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R3) {
			
				if(registers[3]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[3]->v.i = registers[3]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[3]->v.f = registers[3]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[3]->type = FLOAT;
					registers[3]->v.f = (float)registers[3]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[3]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[3]->v.f = registers[3]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R4) {
			
				if(registers[4]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[4]->v.i = registers[4]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[4]->v.f = registers[4]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[4]->type = FLOAT;
					registers[4]->v.f = (float)registers[4]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[4]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[4]->v.f = registers[4]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R5) {

				if(registers[5]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[5]->v.i = registers[5]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[5]->v.f = registers[5]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[5]->type = FLOAT;
					registers[5]->v.f = (float)registers[5]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[5]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[5]->v.f = registers[5]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R6) {
			
				if(registers[6]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[6]->v.i = registers[6]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[6]->v.f = registers[6]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[6]->type = FLOAT;
					registers[6]->v.f = (float)registers[6]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[6]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[6]->v.f = registers[6]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R7) {
			
				if(registers[7]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{

					registers[7]->v.i = registers[7]->v.i * registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[7]->v.f = registers[7]->v.f * registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[7]->type = FLOAT;
					registers[7]->v.f = (float)registers[7]->v.i * registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[7]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[7]->v.f = registers[7]->v.f * (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next->next;
				i++;
			}
		}
		else if (tok->type == OPCODE && tok->v.op == DIV)	{
			if (tok->next->type == REGISTER && tok->next->v.r == A) {
			
				if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[0]->type = FLOAT;
					registers[0]->v.f = (float)registers[0]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					registers[0]->v.i = (int) NULL;
					i++;
				}
				else if(registers[0]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[0]->v.f = registers[0]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[0]->type = FLOAT;
					registers[0]->v.f = (float)registers[0]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[0]->v.i = (int)NULL;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[0]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[0]->v.f = registers[0]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R1) {
			
				if(registers[1]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[1]->type = FLOAT;
					registers[1]->v.f = (float)registers[1]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					registers[1]->v.i = (int)NULL;
					i++;
				}
				else if(registers[1]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[1]->v.f = registers[1]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[1]->type = FLOAT;
					registers[1]->v.f = (float)registers[1]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[1]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[1]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[1]->v.f = registers[1]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R2) {
			
				if(registers[2]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[2]->type = FLOAT;
					registers[2]->v.f = (float)registers[2]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					registers[2]->v.i = (int)NULL;
					i++;
				}
				else if(registers[2]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[2]->v.f = registers[2]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[2]->type = FLOAT;
					registers[2]->v.f = (float)registers[2]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[2]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[2]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[2]->v.f = registers[2]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R3) {
			
				if(registers[3]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[3]->type = FLOAT;
					registers[3]->v.i = (float)registers[3]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[3]->v.f = registers[3]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[3]->type = FLOAT;
					registers[3]->v.f = (float)registers[3]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[3]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[3]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[3]->v.f = registers[3]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R4) {
			
				if(registers[4]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[4]->type = FLOAT;
					registers[4]->v.i = (float)registers[4]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[4]->v.f = registers[4]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[4]->type = FLOAT;
					registers[4]->v.f = (float)registers[4]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[4]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[4]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[4]->v.f = registers[4]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R5) {

				if(registers[5]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[5]->type = FLOAT;
					registers[5]->v.i = (float)registers[5]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[5]->v.f = registers[5]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[5]->type = FLOAT;
					registers[5]->v.f = (float)registers[5]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[5]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[5]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[5]->v.f = registers[5]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R6) {
			
				if(registers[6]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[6]->type = FLOAT;
					registers[6]->v.i = (float)registers[6]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[6]->v.f = registers[6]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[6]->type = FLOAT;
					registers[6]->v.f = (float)registers[6]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[6]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[6]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[6]->v.f = registers[6]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R7) {
			
				if(registers[7]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type ==INTEGER)	{
					registers[7]->type = FLOAT;
					registers[7]->v.i = (float)registers[7]->v.i / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{

					registers[7]->v.f = registers[7]->v.f / registers[determine_register(tok->next->next->v.r)]->v.f;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == INTEGER && registers[determine_register(tok->next->next->v.r)]->type == FLOAT)	{
					registers[7]->type = FLOAT;
					registers[7]->v.f = (float)registers[7]->v.i / registers[determine_register(tok->next->next->v.r)]->v.f;
					registers[7]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if(registers[7]->type == FLOAT && registers[determine_register(tok->next->next->v.r)]->type == INTEGER)	{
					
					registers[7]->v.f = registers[7]->v.f / (float)registers[determine_register(tok->next->next->v.r)]->v.i;
					tok = tok->next->next->next;
					i++;
				}
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next->next;
				i++;
			}
		}
		else if (tok->type == OPCODE && tok->v.op == SQRT)	{
			if(tok->next->type == REGISTER && tok->next->v.r == A)	{
				if(registers[0]->type == FLOAT)	{

					registers[0]->v.f = sqrt(registers[0]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[0]->type == INTEGER)	{
					registers[0]->v.f = sqrt((float)registers[0]->v.i);
					tok = tok->next->next;
					registers[0]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R1)	{
			
				if(registers[1]->type == FLOAT)	{

					registers[1]->v.f = sqrt(registers[1]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[1]->type == INTEGER)	{
					registers[1]->v.f = sqrt((float)registers[1]->v.i);
					tok = tok->next->next;
					registers[1]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R2)	{
			
				if(registers[2]->type == FLOAT)	{

					registers[2]->v.f = sqrt(registers[2]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[2]->type == INTEGER)	{
					registers[2]->v.f = sqrt((float)registers[2]->v.i);
					tok = tok->next->next;
					registers[2]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R3)	{
			
				if(registers[3]->type == FLOAT)	{

					registers[3]->v.f = sqrt(registers[3]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[3]->type == INTEGER)	{
					registers[3]->v.f = sqrt((float)registers[3]->v.i);
					tok = tok->next->next;
					registers[3]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R4)	{
			
				if(registers[4]->type == FLOAT)	{

					registers[4]->v.f = sqrt(registers[4]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[4]->type == INTEGER)	{
					registers[4]->v.f = sqrt((float)registers[4]->v.i);
					tok = tok->next->next;
					registers[4]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R5)	{
			
				if(registers[5]->type == FLOAT)	{

					registers[5]->v.f = sqrt(registers[5]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[5]->type == INTEGER)	{
					registers[5]->v.f = sqrt((float)registers[5]->v.i);
					tok = tok->next->next;
					registers[5]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R6)	{
			
				if(registers[6]->type == FLOAT)	{

					registers[6]->v.f = sqrt(registers[6]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[6]->type == INTEGER)	{
					registers[6]->v.f = sqrt((float)registers[6]->v.i);
					tok = tok->next->next;
					registers[6]->v.i = 0;
					i++;
				}
			}
			else if (tok->next->type == REGISTER && tok->next->v.r == R7)	{
			
				if(registers[7]->type == FLOAT)	{

					registers[7]->v.f = sqrt(registers[7]->v.f);
					tok = tok->next->next;
					i++;
				}
				else if(registers[7]->type == INTEGER)	{
					registers[7]->v.f = sqrt((float)registers[7]->v.i);
					tok = tok->next->next;
					registers[7]->v.i = 0;
					i++;
				}
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next;
				i++;
			}
		}
		//Syntax: 'EXP [RegX]' : e ^ (RegX) -> RegX
		else if (tok->type == OPCODE && tok->v.op == EXP)	{
			if (tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == INTEGER)	{
				registers[determine_register(tok->next->v.r)]->type = FLOAT;
				registers[determine_register(tok->next->v.r)]->v.f = (float)exp((double)registers[determine_register(tok->next->v.r)]->v.i);
				registers[determine_register(tok->next->v.r)]->v.i = 0;
				tok = tok->next->next;
				i++;
			}
			else if(tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == FLOAT)	{
			
				registers[determine_register(tok->next->v.r)]->v.f = (float)exp((double)registers[determine_register(tok->next->v.r)]->v.f);
				tok= tok->next->next;
				i++;
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next;
				i++;
			}
		}
		//Syntax: 'Get [RegX]' : print to screen value of RegX
		else if (tok->type == OPCODE && tok->v.op == GET)	{
			printf("Yo ");
			
			if(tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == INTEGER)	{
				printf("that's chill %d ", determine_register(tok->next->v.r));
			
				fprintf(fp, "%d\n", registers[determine_register(tok->next->v.r)]->v.i);
			}
			else if(tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == FLOAT)	{
			
				fprintf(fp, "%f\n", registers[determine_register(tok->next->v.r)]->v.f);
			}
		}
		//Syntax: 'MINUS [RegX] [RegY]' : RegX - RegY -> RegX
		else if (tok->type == OPCODE && tok->v.op == MINUS)	{
			if (tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == INTEGER)	{
			
				registers[determine_register(tok->next->v.r)]->v.i = registers[determine_register(tok->next->v.r)]->v.i - registers[determine_register(tok->next->next->v.r)]->v.i;
				tok = tok->next->next->next;
				i++;
			}
			else if(tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == FLOAT)	{
			
				registers[determine_register(tok->next->v.r)]->v.f = registers[determine_register(tok->next->v.r)]->v.f - registers[determine_register(tok->next->next->v.r)]->v.f;
				tok = tok->next->next->next;
				i++;
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next;
				i++;
			}
		}
		//Syntax: 'POWR [RegX] [RegY]' or 'POWR [RegX] float' : RegX ^ RegY -> RegX or RegX ^ float -> RegX
		else if (tok->type == OPCODE && tok->v.op == POWR)	{
			if (tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == INTEGER)	{	//case when the base register (ie RegX) holds an int that needs to be cast to a float
				if (tok->next->next->type == FLOAT)	{						//case when rasing RegX to a float
					registers[determine_register(tok->next->v.r)]->type = FLOAT;
					registers[determine_register(tok->next->v.r)]->v.f = (float)pow((double)registers[determine_register(tok->next->v.r)]->v.i, tok->next->next->v.f);
					registers[determine_register(tok->next->v.r)]->v.i = 0;
					tok = tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{					//case when rasing RegX to RegY
					registers[determine_register(tok->next->v.r)]->type = FLOAT;
					registers[determine_register(tok->next->v.r)]->v.f = (float)pow((double)registers[determine_register(tok->next->v.r)]->v.f, (double)registers[determine_register(tok->next->next->v.r)]->v.f);//not sure I need to cast second value to a double.
					registers[determine_register(tok->next->v.r)]->v.i = 0;
					tok= tok->next->next->next;
					i++;
				}
			}
			else if(tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == FLOAT)	{	//case when the base register (ie RegX) already holds a float
				if (tok->next->next->type == FLOAT)	{						//case when rasing RegX to a float
					registers[determine_register(tok->next->v.r)]->v.f = (float)pow((double)registers[determine_register(tok->next->v.r)]->v.f, tok->next->next->v.f);
					tok= tok->next->next->next;
					i++;
				}
				else if (tok->next->next->type == REGISTER)	{					//case when rasing RegX to RegY
					registers[determine_register(tok->next->v.r)]->v.f = (float)pow((double)registers[determine_register(tok->next->v.r)]->v.f, (double)registers[determine_register(tok->next->next->v.r)]->v.f);
					tok= tok->next->next->next;
					i++;
				}
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next->next;
				i++;
			}
		}
		//Syntax: 'DEC [RegX]' : RegX - 1 -> RegX.
		else if (tok->type == OPCODE && tok->v.op == DEC)	{
			if (tok->next->type == REGISTER)	{
				registers[determine_register(tok->next->v.r)]->v.i = registers[determine_register(tok->next->v.r)]->v.i - 1;
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next;
				i++;
			}
		}
		//Syntax: 'LOOP [Reg] [Line]' : loop to line, as long as Reg[the count] > 0. Count and line must be integers.
		else if (tok->type == OPCODE && tok->v.op == LOOP)	{
			if (tok->next->type == REGISTER && registers[determine_register(tok->next->v.r)]->type == INTEGER && tok->next->next->type == INTEGER && registers[determine_register(tok->next->v.r)]->v.i > 0)	{
				i = (int)(tok->next->next);
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next->next;
				i++;
			}
		}
		//Syntax: 'LOAD [Reg] [Value]' : Value -> Reg.
		else if (tok->type == OPCODE && tok->v.op == LOAD)	{
			if (tok->next->type == REGISTER && tok->next->next->type == INTEGER)	{
				registers[determine_register(tok->next->v.r)]->v.i = (int)(tok->next->next->v.i);
			}
			else if (tok->next->type == REGISTER && tok->next->next->type == FLOAT)	{
				registers[determine_register(tok->next->v.r)]->v.f = (float)tok->next->next->v.f;
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
			}
			tok = tok->next->next->next;
			i++;
		}
		//Syntax: 'BRA [i-value]' : Will always branch to line i.  i-value must be integer.
		else if (tok->type == OPCODE && tok->v.op == BRA)	{
			if (tok->next == INTEGER)	{
				i = (int)(tok->next);
			}
			else	{
				fprintf(fp,  "Error in program on line %d", i);
				tok = tok->next->next;
				i++;
			}
		}
		//Syntax: 'END' :Ends program
		else if (tok->type == OPCODE && tok->v.op == END)	{
			for (j = 0; j < 10; j++)        {
       				free(registers[j]);
			}
			return;
		}

	}
}
//Searches input to determine if it is an int
int find_char(char *tok)	{

	int maybe;
	int i, j,k,l;
	int size = strlen(tok);
	char test;
	//Searches for ASCII characters before number set
	for(i = 0; i<size; i++)	{
		test = '!';
		for(k = 33; k < 45; k++)	{
			maybe = (int)strchr(tok, test);
			if (maybe != NULL) {
				return 0;
			}
			test++;
		}
	}
		for(i = 0; i<size; i++)	{
		test = '.';
		for(k = 0; k < 1; k++)	{
			maybe = (int)strchr(tok, test);
			if (maybe != NULL) {
				return 0;
			}
			test++;
		}
	}
	//Searches for ASCII characters after number set
	for(j = 0; j<size; j++)	{
		test = ':';
		for(l = 58; l < 126; l++)	{
			maybe = (int)strchr(tok, test);
			if (maybe != NULL) {
				return 0;
			}
			test++;
		}
	}
	return 1;
}
//counts all the decimals in a token
int find_decimal(char *tok)	{

	int maybe;
	int i, j,k,l;
	int size = strlen(tok);
	char test;
	//Searches for ASCII characters before number set
	for(i = 0; i<size; i++)	{
		test = '!';
		for(k = 33; k < 45; k++)	{
			maybe = (int)strchr(tok, test);
			if (maybe != NULL) {
				return 0;
			}
			test++;
		}
	}
	if ((int)strchr(tok, '/') != NULL)	{
		return 0;
	}
	//Searches for ASCII characters after number set
	for(j = 0; j<size; j++)	{
		test = ':';
		for(l = 58; l < 126; l++)	{
			maybe = (int)strchr(tok, test);
			if (maybe != NULL) {
				return 0;
			}
			test++;
		}
	}
	return 1;
}


